﻿using System;

namespace mediaPrime.Sdk
{
    /// <summary>
    /// Available message types of mediaPrime for easier use
    /// </summary>
    public static class MessageTypes
    {
        public static readonly string Default = "Default";
        public static readonly string Notification = "Notification";
        public static readonly string Command = "Command";
        public static readonly string Query = "Query";
        public static readonly string QueryResult = "QueryResult";
    }

    /// <summary>
    /// Available message receivers of mediaPrime for easier use
    /// </summary>
    public static class MessageReceivers
    {
        public static readonly string mediaPrime = "mediaPrime";
        public static readonly string mediaPrimePluginTV = "mediaPrime.Plugin.TV";
        // TODO: Add more when available
    }

    /// <summary>
    /// A message to communicate between Plugins and mediaPrime
    /// </summary>
    public class Message
    {
        public string Id { get; internal set; }
        public string Sender { get; internal set; }
        public string Receiver { get; set; }

        public string Type { get; set; }

        public object Content { get; set; }

        /// <summary>
        /// If the message is an answer to a previous message, this property contains the previous message
        /// </summary>
        public Message RelatedMessage { get; internal set; }

        public Message()
        {
            Id = Guid.NewGuid().ToString();
            Type = MessageTypes.Default;
            Receiver = MessageReceivers.mediaPrime;
        }
    }

    /// <summary>
    /// This class is used to send a command to another Plugin or to mediaPrime
    /// </summary>
    public class Command
    {
        public string Type { get; set; }
        public object Parameters { get; set; }
    }

    /// <summary>
    /// This class is used to send a global notification to the user
    /// </summary>
    public class Notification
    {
        public string Title { get; set; }
        public string Content { get; set; }

        /// <summary>
        /// The date and time when it happened. If not set, the value is DateTime.Now
        /// </summary>
        public DateTime Date { get; set; }

        /// <summary>
        /// When the user clicks on the notification, the Plugin will be notifed and may use this property to handle further action
        /// </summary>
        public string Action { get; set; }

        /// <summary>
        /// Set this property to true, if you want to show your Plugin after the user clicks on your notification. If set to false you will be still notified to handle the Action
        /// </summary>
        public bool ShowPlugin { get; set; }

        /// <summary>
        /// When this notification was created
        /// </summary>
        internal DateTime Timestamp { get; set; }

        public Notification()
        {
            Timestamp = DateTime.Now;
            Date = Timestamp;
        }
    }

    public class Query
    {
        public string Type { get; set; }
        public object Parameters { get; set; }
    }

    public class QueryResult
    {
        public string Type { get; set; }
        public object Result { get; set; }

        public Exception Exception { get; set; }
    }

    public static class QueryTypes
    {
        public static readonly string mediaPrimeVersion = "mediaPrimeVersion";
        public static readonly string CurrentRunningPlugin = "CurrentRunningPlugin";
        internal static readonly string AvailablePlugins = "AvailablePlugins";
        public static readonly string LoadedPlugins = "LoadedPlugins";

        internal static readonly string CustomSettingDisplayName = "CustomSettingDisplayName";
        internal static readonly string CustomSettingsDialog = "CustomSettingsDialog";

        // TODO: Add more on demand
    }

}
